package com.learning.security.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.learning.security.dal.dataobject.MenuRoleDO;
import com.learning.security.dal.dataobject.RoleDO;
import com.learning.security.dal.mysql.MenuRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xxx
 * @since 2024-09-20
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRoleDO> implements MenuRoleService {

    @Autowired
    private RoleService roleService;

    @Override
    public List<RoleDO> listRolesByMenuId(Integer id) {
        LambdaQueryWrapper<MenuRoleDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MenuRoleDO::getMid, id);
        List<MenuRoleDO> menuRoleDOS = list(queryWrapper);
        List<Integer> roleIds = menuRoleDOS.stream().map(MenuRoleDO::getRid).collect(Collectors.toList());
        return roleService.listByIds(roleIds);
    }
}
